/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CrearTareaView.java
 *
 * Created on 15-ene-2011, 12:29:11
 */
package Vista.Tarea;

import Modelo.Entidades.Pregunta;
import Modelo.Entidades.Tarea;
import java.io.Serializable;
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import javax.swing.JOptionPane;

/*
 *  Proyecto eJAM [G12]
 *  Miembros:
 *      - Javier Ruiz Hidalgo
 *      - Adrian Ramos Cápitas
 *      - Miguel Alejandro Esteban Ordóñez
 */

public class CrearTareaView extends javax.swing.JPanel {

    private TareaViewImpl view;
    private boolean confirmacion = true;
    public List<Pregunta> preguntas;

    /** Creates new form CrearTareaView */
    public CrearTareaView(TareaViewImpl view) {
        initComponents();
        this.view = view;
        preguntas = new ArrayList();

        this.bloquearCampos();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        GruoBotonesTipo = new javax.swing.ButtonGroup();
        GrupoBotonesError = new javax.swing.ButtonGroup();
        jPanelComprobacion = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jNombre = new javax.swing.JTextField();
        jSemaforo = new javax.swing.JPanel();
        jComprobar = new javax.swing.JButton();
        jPanelDatos = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jRadioOrdinaria = new javax.swing.JRadioButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jFecha = new javax.swing.JTextField();
        jHora = new javax.swing.JTextField();
        jDuracion = new javax.swing.JTextField();
        jPanelPreguntas = new javax.swing.JPanel();
        jNPreguntas = new javax.swing.JLabel();
        jPanelOrdinaria = new javax.swing.JPanel();
        jInsertarPreguntas = new javax.swing.JButton();
        jPanelFinal = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jPreguntaPorTarea = new javax.swing.JTextField();
        jAñadirPreguntas = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel7 = new javax.swing.JLabel();
        jRadioErrorNo = new javax.swing.JRadioButton();
        jRadioError1_2 = new javax.swing.JRadioButton();
        jRadioError1_3 = new javax.swing.JRadioButton();
        jRadioError1_4 = new javax.swing.JRadioButton();
        jRadioErrorOtro = new javax.swing.JRadioButton();
        jTextoErrorOtro = new javax.swing.JTextField();
        jRadioFinal = new javax.swing.JRadioButton();
        jSeparator2 = new javax.swing.JSeparator();
        jBorrar = new javax.swing.JButton();
        jAceptar = new javax.swing.JButton();

        setPreferredSize(new java.awt.Dimension(700, 600));

        jPanelComprobacion.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Comprobación de Nombre", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jLabel1.setText("Nombre:");

        jSemaforo.setBackground(java.awt.Color.yellow);
        jSemaforo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        javax.swing.GroupLayout jSemaforoLayout = new javax.swing.GroupLayout(jSemaforo);
        jSemaforo.setLayout(jSemaforoLayout);
        jSemaforoLayout.setHorizontalGroup(
            jSemaforoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 19, Short.MAX_VALUE)
        );
        jSemaforoLayout.setVerticalGroup(
            jSemaforoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 17, Short.MAX_VALUE)
        );

        jComprobar.setText("Comprobar");
        jComprobar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComprobarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelComprobacionLayout = new javax.swing.GroupLayout(jPanelComprobacion);
        jPanelComprobacion.setLayout(jPanelComprobacionLayout);
        jPanelComprobacionLayout.setHorizontalGroup(
            jPanelComprobacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelComprobacionLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jSemaforo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jComprobar, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanelComprobacionLayout.setVerticalGroup(
            jPanelComprobacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelComprobacionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelComprobacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jComprobar)
                    .addGroup(jPanelComprobacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jSemaforo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanelComprobacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelDatos.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jLabel2.setText("Tipo Tarea:");

        GruoBotonesTipo.add(jRadioOrdinaria);
        jRadioOrdinaria.setSelected(true);
        jRadioOrdinaria.setText("Ordinaria");
        jRadioOrdinaria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioOrdinariaActionPerformed(evt);
            }
        });

        jLabel3.setText("Fecha Límite:");

        jLabel4.setText("Hora Límite:");

        jLabel5.setText("Duración(min): ");

        jFecha.setText("DD/MM/AAAA");
        jFecha.setEnabled(false);

        jHora.setText("HH:MM");
        jHora.setEnabled(false);

        jDuracion.setEnabled(false);

        jPanelPreguntas.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Nº Preguntas", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(51, 51, 51))); // NOI18N

        jNPreguntas.setFont(new java.awt.Font("Arial Black", 1, 18));
        jNPreguntas.setForeground(java.awt.Color.darkGray);
        jNPreguntas.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jNPreguntas.setText("0");

        javax.swing.GroupLayout jPanelPreguntasLayout = new javax.swing.GroupLayout(jPanelPreguntas);
        jPanelPreguntas.setLayout(jPanelPreguntasLayout);
        jPanelPreguntasLayout.setHorizontalGroup(
            jPanelPreguntasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPreguntasLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jNPreguntas, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelPreguntasLayout.setVerticalGroup(
            jPanelPreguntasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelPreguntasLayout.createSequentialGroup()
                .addComponent(jNPreguntas, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanelOrdinaria.setBorder(javax.swing.BorderFactory.createTitledBorder("Ordinaria"));

        jInsertarPreguntas.setText("Insertar Preguntas y Respuestas");
        jInsertarPreguntas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jInsertarPreguntasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelOrdinariaLayout = new javax.swing.GroupLayout(jPanelOrdinaria);
        jPanelOrdinaria.setLayout(jPanelOrdinariaLayout);
        jPanelOrdinariaLayout.setHorizontalGroup(
            jPanelOrdinariaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelOrdinariaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jInsertarPreguntas, javax.swing.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelOrdinariaLayout.setVerticalGroup(
            jPanelOrdinariaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOrdinariaLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jInsertarPreguntas, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelFinal.setBorder(javax.swing.BorderFactory.createTitledBorder("Final"));

        jLabel6.setText("Nº Preguntas Por Cada Tarea:");

        jPreguntaPorTarea.setEnabled(false);

        jAñadirPreguntas.setText("Añadir");
        jAñadirPreguntas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jAñadirPreguntasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelFinalLayout = new javax.swing.GroupLayout(jPanelFinal);
        jPanelFinal.setLayout(jPanelFinalLayout);
        jPanelFinalLayout.setHorizontalGroup(
            jPanelFinalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFinalLayout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPreguntaPorTarea, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(jAñadirPreguntas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelFinalLayout.setVerticalGroup(
            jPanelFinalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFinalLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanelFinalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jAñadirPreguntas)
                    .addComponent(jPreguntaPorTarea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addContainerGap(28, Short.MAX_VALUE))
        );

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setText("Penalización Por Respuestas Erroneas");

        GrupoBotonesError.add(jRadioErrorNo);
        jRadioErrorNo.setSelected(true);
        jRadioErrorNo.setText("No");
        jRadioErrorNo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioErrorNoActionPerformed(evt);
            }
        });

        GrupoBotonesError.add(jRadioError1_2);
        jRadioError1_2.setText("1/2");
        jRadioError1_2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioError1_2ActionPerformed(evt);
            }
        });

        GrupoBotonesError.add(jRadioError1_3);
        jRadioError1_3.setText("1/3");
        jRadioError1_3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioError1_3ActionPerformed(evt);
            }
        });

        GrupoBotonesError.add(jRadioError1_4);
        jRadioError1_4.setText("1/4");
        jRadioError1_4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioError1_4ActionPerformed(evt);
            }
        });

        GrupoBotonesError.add(jRadioErrorOtro);
        jRadioErrorOtro.setText("Otro (%)");
        jRadioErrorOtro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioErrorOtroActionPerformed(evt);
            }
        });

        jTextoErrorOtro.setEnabled(false);

        GruoBotonesTipo.add(jRadioFinal);
        jRadioFinal.setText("Final");
        jRadioFinal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioFinalActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelDatosLayout = new javax.swing.GroupLayout(jPanelDatos);
        jPanelDatos.setLayout(jPanelDatosLayout);
        jPanelDatosLayout.setHorizontalGroup(
            jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDatosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDatosLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(jRadioOrdinaria)
                        .addGap(18, 18, 18)
                        .addComponent(jRadioFinal))
                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
                    .addGroup(jPanelDatosLayout.createSequentialGroup()
                        .addComponent(jRadioErrorNo)
                        .addGap(18, 18, 18)
                        .addComponent(jRadioError1_2)
                        .addGap(18, 18, 18)
                        .addComponent(jRadioError1_3)
                        .addGap(18, 18, 18)
                        .addComponent(jRadioError1_4)
                        .addGap(18, 18, 18)
                        .addComponent(jRadioErrorOtro)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextoErrorOtro, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelDatosLayout.createSequentialGroup()
                            .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel3)
                                .addComponent(jLabel4)
                                .addComponent(jLabel5))
                            .addGap(18, 18, 18)
                            .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jDuracion)
                                .addComponent(jHora, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                                .addComponent(jFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(29, 29, 29)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanelOrdinaria, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelPreguntas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelFinal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanelDatosLayout.setVerticalGroup(
            jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDatosLayout.createSequentialGroup()
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDatosLayout.createSequentialGroup()
                        .addComponent(jPanelPreguntas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelOrdinaria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelDatosLayout.createSequentialGroup()
                        .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jRadioOrdinaria)
                            .addComponent(jRadioFinal))
                        .addGap(18, 18, 18)
                        .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jDuracion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7)
                        .addGap(18, 18, 18)
                        .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jRadioErrorNo)
                            .addComponent(jRadioError1_2)
                            .addComponent(jRadioError1_3)
                            .addComponent(jRadioError1_4)
                            .addComponent(jRadioErrorOtro)
                            .addComponent(jTextoErrorOtro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jBorrar.setText("Borrar");
        jBorrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBorrarActionPerformed(evt);
            }
        });

        jAceptar.setText("Aceptar");
        jAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelDatos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelComprobacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 700, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jAceptar)
                        .addGap(18, 18, 18)
                        .addComponent(jBorrar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelComprobacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanelDatos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBorrar)
                    .addComponent(jAceptar))
                .addContainerGap(119, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioOrdinariaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioOrdinariaActionPerformed
        if (this.jRadioOrdinaria.isSelected() && confirmacion == false) {
            this.jPreguntaPorTarea.disable();
            this.jInsertarPreguntas.enable();
        } else {
            this.jInsertarPreguntas.disable();
        }
    }//GEN-LAST:event_jRadioOrdinariaActionPerformed

    private void jRadioFinalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioFinalActionPerformed
        if (this.jRadioFinal.isSelected() && confirmacion == false) {
            this.jPreguntaPorTarea.enable();
            this.jInsertarPreguntas.disable();
        } else {
            this.jPreguntaPorTarea.disable();
        }
    }//GEN-LAST:event_jRadioFinalActionPerformed

    private void jRadioErrorOtroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioErrorOtroActionPerformed
        if (this.jRadioErrorOtro.isSelected() && confirmacion == false) {
            this.jTextoErrorOtro.enable();
        } else {
            this.jTextoErrorOtro.disable();
        }
    }//GEN-LAST:event_jRadioErrorOtroActionPerformed

    private void jComprobarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComprobarActionPerformed

        if (this.jNombre.getText().equals("")) {
            this.bloquearCampos();
            jSemaforo.setBackground(java.awt.Color.RED);
            JOptionPane.showMessageDialog(null, "Error: Nombre Vacio");
        } else {
            confirmacion = this.view.getModel().compruebaTarea(this.jNombre.getText());

            if (confirmacion == false) {
                this.desbloquearCampos();
                jSemaforo.setBackground(java.awt.Color.GREEN);
                jNombre.disable();
            } else {
                this.bloquearCampos();
                jSemaforo.setBackground(java.awt.Color.RED);
                JOptionPane.showMessageDialog(null, "Error: Nombre Registrado");
            }
        }
    }//GEN-LAST:event_jComprobarActionPerformed

    private void jAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAceptarActionPerformed
        Date fecha = compruebaFechayHora(this.jFecha.getText(), this.jHora.getText());
        boolean error = false;
        double c_error = 0;
        String errores = "";
        int duracion = 0;
        String tipo;
        Time time;

        //Tratamiento de Errores
        if (fecha == null) {
            errores += "Error: Formato de Fecha o Hora Incorrecto\n";
            error = true;
        }
        if(this.jRadioErrorOtro.isSelected()){
            if(this.jTextoErrorOtro.getText().equals("")){
                errores += "Error: Campo Otro Porcentaje Error Vacio\n";
                error = true;
            }
            else{
                int aux = Integer.parseInt(this.jTextoErrorOtro.getText());
                if(aux < 100 && aux > 0){
                    c_error = (double)aux / 100.0;
                }
                else{
                    errores += "Error: Porcentaje Incorrecto\n";
                    error = true;
                }
            }
        }
        else{
            if(this.jRadioErrorNo.isSelected()){
                c_error = 0;
            }
            else{
                if(this.jRadioError1_2.isSelected()){
                c_error = 0.5;
                }
                else{
                    if(this.jRadioError1_3.isSelected()){
                        c_error = 0.33f;
                    }
                    else{
                        if(this.jRadioError1_4.isSelected()){
                            c_error = 0.25;
                        }
                    }
                }
            }
        }

        try{
            duracion = Integer.parseInt(this.jDuracion.getText());

            if(duracion <= 0){
                errores += "Error: Duración incorrecta\n";
                error = true;
            }
        }
        catch(Exception ex){
            errores += "Error: Duración incorrecta\n";
        }

        if (this.jRadioOrdinaria.isSelected() && preguntas.isEmpty()) {
            errores += "Error: Introduzca Preguntas y Respuestas\n";
            error = true;
        }

        //Tratamiento de Datos
        if(error == false){
            List<Serializable> datos = new ArrayList();

            datos.add(this.jNombre.getText());

            if (this.jRadioOrdinaria.isSelected()) {
                tipo = "Ordinaria";
            }
            else {
                tipo = "Final";
            }

            time = new Time(0, Integer.parseInt(this.jDuracion.getText()), 0);

            this.view.fireNuevaTareaGesture(this.jNombre.getText(), tipo, time, new Date(), fecha, c_error, preguntas);
            this.removeAll();
            this.initComponents();
        }
        else{
            JOptionPane.showMessageDialog(null, errores);
        }
    }//GEN-LAST:event_jAceptarActionPerformed

    private void jAñadirPreguntasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAñadirPreguntasActionPerformed
        if(this.jRadioFinal.isSelected()){
            int[] nAleatorios;
            int n, iSuper = 0;
            List<Tarea> tareas;
            Pregunta pregunta = null;
            preguntas.clear();

            if (this.jRadioFinal.isSelected()) {
                n = Integer.parseInt(this.jPreguntaPorTarea.getText());

                if (n > 0) {
                    tareas = this.view.getModel().obtieneTareasByTipo("Ordinaria");

                    for (Tarea t : tareas) {
                        if (t.getPreguntas().size() > n) {
                            //Inserción de Preguntas Aleatorias
                            nAleatorios = genera_aleatorios(n, t.getPreguntas().size());

                            for (int i = 0; i < n; i++) {
                                pregunta = t.getPreguntas().get(nAleatorios[i]);
                                pregunta.setNumP(iSuper);
                                preguntas.add(pregunta);
                                iSuper++;
                            }
                        } else {
                            //Inserción de Preguntas Directa
                            for (int i = 0; i < n; i++) {
                                pregunta = t.getPreguntas().get(i);
                                pregunta.setNumP(iSuper);
                                preguntas.add(pregunta);
                                iSuper++;
                            }
                        }
                    }

                } else {
                    JOptionPane.showMessageDialog(null, "Error: Introduzca Nº de Preguntas Por Tarea");
                }
            }

            this.cuentaPreguntas();
        }
    }//GEN-LAST:event_jAñadirPreguntasActionPerformed

    private void jInsertarPreguntasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jInsertarPreguntasActionPerformed
        if(this.jRadioOrdinaria.isSelected()){
            InsercionPreguntasRespuestas frameEmergente = new InsercionPreguntasRespuestas(this);
        }
    }//GEN-LAST:event_jInsertarPreguntasActionPerformed

    private void jRadioErrorNoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioErrorNoActionPerformed
        this.jTextoErrorOtro.setText("");
        this.jTextoErrorOtro.disable();
    }//GEN-LAST:event_jRadioErrorNoActionPerformed

    private void jRadioError1_2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioError1_2ActionPerformed
        this.jTextoErrorOtro.setText("");
        this.jTextoErrorOtro.disable();
    }//GEN-LAST:event_jRadioError1_2ActionPerformed

    private void jRadioError1_3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioError1_3ActionPerformed
        this.jTextoErrorOtro.setText("");
        this.jTextoErrorOtro.disable();
    }//GEN-LAST:event_jRadioError1_3ActionPerformed

    private void jRadioError1_4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioError1_4ActionPerformed
        this.jTextoErrorOtro.setText("");
        this.jTextoErrorOtro.disable();
    }//GEN-LAST:event_jRadioError1_4ActionPerformed

    private void jBorrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBorrarActionPerformed
        this.removeAll();
        this.initComponents();
    }//GEN-LAST:event_jBorrarActionPerformed

    private void desbloquearCampos() {
        this.jHora.enable();
        this.jFecha.enable();
        this.jDuracion.enable();
        this.jRadioError1_2.enable();
        this.jRadioError1_3.enable();
        this.jRadioError1_4.enable();
        this.jRadioErrorOtro.enable();
        this.jRadioErrorNo.enable();
        this.jInsertarPreguntas.enable();
        this.jRadioFinal.enable();
        this.jRadioOrdinaria.enable();
    }

    private void bloquearCampos() {
        this.jHora.disable();
        this.jFecha.disable();
        this.jDuracion.disable();
        this.jRadioError1_2.disable();
        this.jRadioError1_3.disable();
        this.jRadioError1_4.disable();
        this.jRadioErrorOtro.disable();
        this.jRadioErrorNo.disable();
        this.jInsertarPreguntas.enable(false);
        this.jRadioFinal.disable();
        this.jRadioOrdinaria.disable();
    }

    //Funcion que valida una Fecha y Hora concreta
    private Date compruebaFechayHora(String fechaString, String horaString) {
        Date fecha = null;
        String cadena = fechaString + " " + horaString;

        try {
            SimpleDateFormat formatoFecha = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.getDefault());
            formatoFecha.setLenient(false);
            formatoFecha.parse(cadena);
            fecha = formatoFecha.parse(cadena);

            if (fecha.before(new Date()) == true) {
                fecha = null;
            }

        } catch (Exception e) {
            fecha = null;
        }

        return fecha;
    }

    //Funcion que actualiza el contador de Preguntas jNPReguntas
    public void cuentaPreguntas() {
        this.jNPreguntas.setText(String.valueOf(preguntas.size()));
    }

    //Funcion que genera números aleatorios
    public int[] genera_aleatorios(int n, int tam) {
        int[] numeros = new int[n];
        int num;
        boolean valido;

        for (int i = 0; i < n; i++) {
            do {
                valido = false;
                num = (int) (Math.random() * tam);
                if (is_valido(numeros, num)) {
                    numeros[i] = num;
                    valido = true;
                }
            } while (valido == false);
        }

        return numeros;
    }

    //Funcion que comprueba si el numero ya pertenece al vector
    public boolean is_valido(int[] numeros, int num) {
        boolean confirm = true;

        for (int j = 0; j < numeros.length; j++) {
            if (num == numeros[j]) {
                confirm = false;
            }
        }

        return confirm;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup GruoBotonesTipo;
    private javax.swing.ButtonGroup GrupoBotonesError;
    private javax.swing.JButton jAceptar;
    private javax.swing.JButton jAñadirPreguntas;
    private javax.swing.JButton jBorrar;
    private javax.swing.JButton jComprobar;
    private javax.swing.JTextField jDuracion;
    private javax.swing.JTextField jFecha;
    private javax.swing.JTextField jHora;
    private javax.swing.JButton jInsertarPreguntas;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jNPreguntas;
    private javax.swing.JTextField jNombre;
    private javax.swing.JPanel jPanelComprobacion;
    private javax.swing.JPanel jPanelDatos;
    private javax.swing.JPanel jPanelFinal;
    private javax.swing.JPanel jPanelOrdinaria;
    private javax.swing.JPanel jPanelPreguntas;
    private javax.swing.JTextField jPreguntaPorTarea;
    private javax.swing.JRadioButton jRadioError1_2;
    private javax.swing.JRadioButton jRadioError1_3;
    private javax.swing.JRadioButton jRadioError1_4;
    private javax.swing.JRadioButton jRadioErrorNo;
    private javax.swing.JRadioButton jRadioErrorOtro;
    private javax.swing.JRadioButton jRadioFinal;
    private javax.swing.JRadioButton jRadioOrdinaria;
    private javax.swing.JPanel jSemaforo;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextField jTextoErrorOtro;
    // End of variables declaration//GEN-END:variables
}
